<template>
<div>
    <van-sticky>
    <van-nav-bar
      title="登录"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    </van-sticky>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Form } from "vant";
import { Field, Sticky, Radio, RadioGroup, Toast, NavBar } from "vant";
import { LOADDATA } from "../../store/actionTypes";
import axios from "axios";
import { mapActions, mapState } from "vuex";
Vue.use(Form);
Vue.use(NavBar);
Vue.use(Field);
Vue.use(Sticky);
Vue.use(Radio);
Vue.use(RadioGroup);
Vue.use(Toast);
export default {
  data() {
    return {
      username: "",
      password: "",
      phonenum: "",
      sex: "",
    };
  },
  //   computed: { ...mapState("login", "item") },
  methods: {
    // ...mapActions("login", [LOADDATA]),
    onClickLeft() {
      this.$router.back();
    },
    onSubmit(values) {
      console.log(values);
      axios
        .post("http://10.9.47.131:3000/admin/table/check", values)
        .then((ret) => {
          Toast(ret.data.msg);
          if (ret.data.code === 200) {
            this.$store.dispatch(`login/${LOADDATA}`, values.username, {
              root: true,
            });
            this.$router.push("/");
          }
        });
    },
  },
};
</script >

<style lang="stylus" scoped>
.nav
  position sticky
  top 0
  height 0.45rem
  text-align center
  line-height 0.45rem
  background-color white
  h1
    font-size 0.16rem
    font-weight 400
</style>